﻿IF EXISTS (SELECT * FROM sysobjects WHERE type = 'P' AND name = 'proc_cm_AddSiteMapNode')
BEGIN
    PRINT 'Dropping Procedure proc_cm_AddSiteMapNode'
    DROP  Procedure  proc_cm_AddSiteMapNode
END
GO

PRINT 'Creating Procedure proc_cm_AddSiteMapNode'
GO

CREATE PROCEDURE [dbo].[proc_cm_AddSiteMapNode]
	@node_id uniqueidentifier
	, @title nvarchar(255)
	, @parent_node_id uniqueidentifier
AS
BEGIN
	SET NOCOUNT ON

	DECLARE @pDisplayOrderNum INT

	SELECT @pDisplayOrderNum = ISNULL(MAX([display_order_num]),0) + 1
	FROM [dbo].[tbl_sitemap]
	WHERE [parent_node_id] = @parent_node_id

	INSERT INTO [dbo].[tbl_sitemap]
	(
		[node_id]
		,[node_title]
		,[parent_node_id]
		,[display_order_num]
	)
	VALUES
	(
		@node_id
		,@title
		,@parent_node_id
		,@pDisplayOrderNum
	)
END
GO

GRANT EXEC ON dbo.proc_cm_AddSiteMapNode TO PUBLIC
GO
